package edu.guigu.servicedemo;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * AIDL只可传递它所认识的基本数据类型和经过Parcelable序列化的数据
 * 序列化：要我们来手动进行 “打包” 和 “解包” 的工作
* @Description: (用一句话描述)
* @author yuanc
* @date 2025/9/5 16:19
*/
public class MyData implements Parcelable {
    private int id;
    private String content;

    public MyData(int id, String content) {
        this.id = id;
        this.content = content;
    }

    protected MyData(Parcel in) {
        id = in.readInt();
        content = in.readString();
    }

    // 有序"打包" (拿的时候，按顺序拿到)
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(content);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    // "解包"
    public static final Creator<MyData> CREATOR = new Creator<MyData>() {
        @Override
        public MyData createFromParcel(Parcel in) {
            return new MyData(in);
        }

        @Override
        public MyData[] newArray(int size) {
            return new MyData[size];
        }
    };

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
